package com.remon.quartz.config.consumer;

import com.alibaba.fastjson.JSON;
import com.remon.quartz.entity.MessageNotice;
import com.remon.quartz.jpush.JpushBulider;
import com.remon.quartz.util.ObjAnalysis;
import com.remon.quartz.util.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;

import java.util.HashMap;
import java.util.Map;

/**
 * 普通数据
 */
public class PushConsumer implements ChannelAwareMessageListener {

    private Logger logger = LoggerFactory.getLogger(PushConsumer.class);

    @Override
    public void onMessage(Message message, com.rabbitmq.client.Channel channel) throws Exception {

        String jsonStr = new String(message.getBody());
        System.out.println("收到数据JSONSTR" + jsonStr);
        MessageNotice messageNotice = JSON.parseObject(jsonStr, MessageNotice.class);
        JpushBulider jpushBulider = SpringUtils.context.getBean(JpushBulider.class);
        jpushBulider.send(messageNotice.getTag(), messageNotice.getTitle(), ObjAnalysis.ConvertObjToMap(messageNotice));
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true); //确认消息成功消费

    }
}  